package com.xxyy.mylive.ui.activity;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ProgressBar;

import com.xxyy.mylive.R;
import com.xxyy.mylive.ui.BaseActivity;

public class WebActivity extends BaseActivity {
    private WebView mShareWebView;
    private ImageButton btnBack;
    private ProgressBar progressBar;
    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_web);
    }

    @Override
    protected void initUI() {
        mShareWebView = (WebView) findViewById(R.id.webview_share);
        btnBack = (ImageButton) findViewById(R.id.btn_back);
        progressBar = (ProgressBar) findViewById(R.id.pb_loading_webview);
    }

    @Override
    protected void setListener() {
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });
    }

    @Override
    protected void initData() {
        String webUrl = getIntent().getStringExtra("web_url");
        mShareWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }
        });
        mShareWebView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                if (newProgress != 100) {
                    progressBar.setVisibility(View.VISIBLE);
                    progressBar.setProgress(newProgress);
                } else {
                    progressBar.setVisibility(View.GONE);
                }
            }
        });
        //开启js
        mShareWebView.getSettings().setJavaScriptEnabled(true);
        mShareWebView.loadUrl(webUrl);
    }
}
